package com.hup.utils.selenium.exception;

import com.hup.utils.commons.exception.ErrParserRegister;
import com.hup.utils.commons.exception.ExceptionMsgParser;
import org.openqa.selenium.WebDriverException;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hugan
 * @date 2020/3/21
 */
public class WebDriverErrParser implements ErrParserRegister {
    @Override
    public List<ExceptionMsgParser> getParsers() {
        List<ExceptionMsgParser> res = new ArrayList<>();
        res.add(new WebDriverErr());
        return res;
    }

    private static class WebDriverErr implements ExceptionMsgParser<WebDriverException> {

        @Override
        public String getMsg(WebDriverException e) {
            String message = e.getMessage();
            //原始的message长得恐怖,这里只要第一行
            int indexOf = message.indexOf("\n");
            if (indexOf != -1) {
                return message.substring(0, indexOf);
            }
            return message;
        }
    }

}
